import React from 'react';
// import { Icon } from '@/pages/Recruitment/components';
import { TextareaItem, Toast } from 'antd-mobile';
import { PageWrap, Button, EditListItem, Picker } from '@/pages/RecruitEmail/mobile/components';
import { createForm } from 'rc-form';
import { acceptRecruitmentByEncryptId } from '@/pages/RecruitEmail/service/user';
import { pushRoute } from '@/pages/RecruitEmail/utils';
import { withRouter } from 'umi';
import styles from './index.less';

function InterviewOfferRefuse({ form, location }) {
    const { query } = location;
    const { nid, id } = query;
    const { getFieldProps } = form;
    const listReason = [
        {
            label: '已找到新工作',
            value: 1
        },
        {
            label: '留在原公司',
            value: 2
        },
        {
            label: '办公地点较远',
            value: 3
        },
        {
            label: '其他',
            value: 99
        }
    ];
    const submitReject = () => {
        form.validateFields(async (err, values) => {
            if (!err) {
                console.log(values);
                Toast.loading('提交中...', 5000);
                // 拒绝录用：employState 8
                const res = await acceptRecruitmentByEncryptId({
                    ...values,
                    employId: nid,
                    employState: 8,
                    terminationType: values?.terminationType[0]
                });

                if (res.code === 10000) {
                    Toast.hide();
                    Toast.success('操作成功');
                    Toast.hide();
                    pushRoute({
                        pathname: '/recruitment',
                        query: {
                            nid,
                            id
                        }
                    });
                } else {
                    // message.error(res.msg);
                    Toast.hide();
                    // Toast.fail();
                }
            }
        });
    };
    return (
        <PageWrap
            title="拒绝录用"
            style={{ width: '100%', height: '100%' }}
            footer={
                <div className={styles.footer}>
                    <Button
                        type="primary"
                        style={{ flex: 1 }}
                        disabled={!form.getFieldValue('terminationType')}
                        // disabled={declareDetail?.settingSwitch === 1 && !form.getFieldValue('remove')}
                        onClick={submitReject}
                    >
                        提交
                    </Button>
                </div>
            }
        >
            <div className={styles.refuseCon}>
                <Picker
                    style={{ zIndex: 900000 }}
                    title="原因"
                    data={listReason || []}
                    {...getFieldProps('terminationType', {
                        initialValue: '',
                        rules: [{ required: true, message: '请选择原因' }]
                    })}
                >
                    <EditListItem title="原因">请选择</EditListItem>
                </Picker>
                <EditListItem title="备注" showArrow={false} required={false}>
                    <TextareaItem
                        {...getFieldProps('remark', {
                            initialValue: ''
                        })}
                        rows={5}
                        count={800}
                        placeholder="请输入备注"
                    />
                </EditListItem>
            </div>
        </PageWrap>
    );
}
export default withRouter(createForm()(InterviewOfferRefuse));
